package com.nucarf.yc.utils

import org.apache.flink.streaming.api.windowing.time.Time

import java.text.SimpleDateFormat

object DTUtils {

  /**
   * 分精度时间的转换
   *
   * @param time         要转换的时间
   * @param intervalTime 间隔时间段
   * @return
   */
  def accuracyTime(time: Long, intervalTime: Time): Long = {
    val var1: Long = intervalTime.toMilliseconds
    (time / var1 * var1 + var1)
  }

  /**
   * 将时间字段转换成时间戳
   *
   * @param dateStr       时间字段
   * @param formatPattern 要转换时间字段的格式
   * @param offer         时差(单位：毫秒)
   * @return
   */
  def timestampConverter(formatPattern: String, dateStr: String, offer: Long): Long = {
    val simpleDateFormat = new SimpleDateFormat(formatPattern)
    val timestamp = simpleDateFormat.parse(dateStr).getTime
    (timestamp + offer)
  }

  /**
   * 获取当前时间
   *
   * @return
   */
  def now(): Long = System.currentTimeMillis()

  def nowString(): String = {
    val simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss")
    val str: String = simpleDateFormat.format(now())
    str
  }

  def main(args: Array[String]): Unit = {
    print(nowString)
  }
}
